﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Notoric.View.Music.CWNotation.Converters
{
    /// <summary>
    /// Converts a textual dynamic mark expression into the corresponding characters used in MusicalFont.ttf.
    /// </summary>
    public class DynamicMarkConverter : IValueConverter
    {
        #region IValueConverter Members

        /// <inheritdoc/>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string)
            {
                var expression = value.ToString();
                var result = expression.Replace("mp", "P");
                result = result.Replace("mf", "F");
                result = result.Replace("fz", "Z");
                result = result.Replace('r', 'ó');
                result = result.Replace("ppp", "¸");
                result = result.Replace("pp", "¹");
                result = result.Replace("fff", "ì");
                result = result.Replace("ff", "Ä");

                return result;
            }
            else
                return "";
        }

        /// <inheritdoc/>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
